<?php
namespace app\index\model;
use think\Db;
/**
 * Created by Submint Text.
 * User: hetaoren<452649510@qq.com>
 * Date: 2017/03/10
 * Explain: 操作日志业务处理
 */
class LogOperates extends Base{
    /**
	 * 分页
	 */
	public function pageQuery(){
		$startDate = input('get.startDate');
		$endDate = input('get.endDate');
		$where = [];
		if($startDate!='')$where['operateTime'] = ['>=',$startDate." 00:00:00"];
		if($endDate!='')$where[' operateTime'] = ['<=',$endDate." 23:59:59"];			
		$page = $this->where($where)->order('operateId desc')->paginate(input('pagesize/d'))->toArray();
		if(count($page['Rows'])>0){
        	$roles = model('Roles')->listQuery2();
			foreach ($page['Rows'] as $key => $v){
				$staff = model('staffs')->get($v['staffId']);
				$page['Rows'][$key]['staffName'] = $staff['staffName'];
				$page['Rows'][$key]['staffNo'] = $staff['staffNo'];
				$page['Rows'][$key]['staffPhone'] = $staff['staffPhone'];
				$page['Rows'][$key]['roleName'] = $roles[$staff['staffRoleId']];
				$page['Rows'][$key]['menuName'] = model('menus')->where('menuId',$v['menuId'])->value('menuName');
			}
		}
		return $page;		
	}
	
	/**
	 * 新增操作权限
	 */
	public function add($param){
		$data = [];
		$data['staffId'] = (int)session('HTR_STAFF.staffId');
		$data['operateTime'] = date('Y-m-d H:i:s');
		$data['menuId'] = $param['menuId'];
		$data['operateDesc'] = $param['operateDesc'];
		$data['content'] = $param['content'];
		$data['operateUrl'] = $param['operateUrl'];
		$data['operateIP'] = $param['operateIP'];
		$this->create($data);
	}
	
    /**
	 * 清除
	 */
	public function clear(){
		$where['operateTime'] = ['<',date("Y-m-d H:i:s", strtotime('-30 day'))];
		$this->where($where)->delete();
	}
}
